<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改文章模板')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-articleTemplate-edit" th:object="${articleTemplate}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">文章模板名称：</label>
                <div class="col-sm-8">
                    <input id="name" name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标签：</label>
                <div class="col-sm-8">
                    <select id="tags" name="tags"  class="form-control select2-multiple" multiple>
                        <option th:each="tag:${tags}" th:value="${tag.tagId}" th:text="${tag.tagName}" th:selected="${tag.selected}"  th:disabled="${tag.status == '1'}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">共享类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('share_type')}">
                        <input type="radio" th:id="${'shareType_' + dict.dictCode}" name="shareType" th:value="${dict.dictValue}" th:field="*{shareType}">
                        <label th:for="${'shareType_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">权重：</label>
                <div class="col-sm-8">
                    <input name="weight" th:field="*{weight}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最热：</label>
                <div class="col-sm-8">
                    <input id="hotFalg" name="hotFalg" th:field="*{hotFalg}" class="form-control" type="hidden">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="isHot" th:checked="${articleTemplate.hotFalg == 1}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">最新：</label>
                <div class="col-sm-8">
                    <input id="newFlag" name="newFlag" th:field="*{newFlag}" class="form-control" type="hidden">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="isNew" th:checked="${articleTemplate.newFlag == 1}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <script id="editor"  name="content" type="text/plain" ></script>
                    <textarea hidden="text" id="divdata">[[*{content}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: ueditor" />
    <script type="text/javascript">
        var ue = UE.getEditor('editor');
        function getContent() {
            return UE.getEditor('editor').getContent();
        }
        function getContentTxt() {
            return UE.getEditor('editor').getContentTxt();
        }
        $(function(){
            $("#editor").css("height","380px");
            $('#tags').select2({
                placeholder:"请选择标签",
                allowClear: true
            });
            $("#isHot").on("change",function(){
                var v=$(this).prop("checked");
                if(v){
                    $("#hotFlag").val("1");
                }else{
                    $("#hotFlag").val("0");
                }
            });
            $("#isNew").on("change",function(){
                var v=$(this).prop("checked");
                if(v){
                    $("#newFlag").val("1");
                }else{
                    $("#newFlag").val("0");
                }
            });

            //给UEeditor赋值
            var data=$("#divdata").text();
            var ue = UE.getEditor('editor');
            var proinfo=$("#divdata").text();
            ue.ready(function() {//编辑器初始化完成再赋值
                ue.setContent(data);  //赋值给UEditor
            });

        })
        var prefix = ctx + "cms/articleTemplate";
        $("#form-articleTemplate-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                var name=$("#name").val();
                if(isEmpty(name)){
                    Fast.msg_error("请输入标题!"); return;
                }
                var tagIds = $.form.selectSelects("tags");
                if(isEmpty(tagIds)){
                    Fast.msg_error("请选择标签!"); return;
                }
                var c = getContentTxt();
                if (c == '' || c.length == 0) {
                    Fast.msg_error("请输入内容！");
                    return;
                }

                $.operate.save(prefix + "/edit", $('#form-articleTemplate-edit').serialize());
            }
        }
    </script>
</body>
</html>